@Api(value = "模块名", description = "background/模块名")
@RestController
@RequestMapping(value = "/background/dmap-knowledge-server/v1/article")
public class PageFieldBackController {
    @Resource
    private PageFieldService pageFieldService;
    @ResponseBody
    @ApiOperation(value = "新增模块名", notes = "新增模块名")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public BaseVo insertPageField(@RequestBody PageFieldParam param) {
        BaseVo result = new BaseVo();
        if ( param.getPageOperateId() == 0 || StringUtils.isBlank(param.getPageFieldCode())|| StringUtils.isBlank(param.getPageFieldName())|| StringUtils.isBlank(param.getDescription())|| param.getCreateTime() == 0 || param.getUpdateTime() == 0    ){            result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        //进行字符串的数字验证
        int success = pageFieldService.insertPageField(param);
       if (success == 0) {
           result.setCode(Constant.RESPONSE_INSERT_ERROR_CODE);
           result.setMsg(Constant.RESPONSE_INSERT_ERROR_MSG);
        }
        return result;
    }
    @ResponseBody
   @ApiOperation(value = "修改模块名", notes = "修改模块名")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
   public BaseVo updatePageField(@RequestBody PageFieldEditParam  param) {
       BaseVo result = new BaseVo();
        if (StringUtils.isBlank(param.getPageFieldId()) || StringUtils.isNumeric(param.getPageFieldId())|| param.getPageOperateId() == 0 || StringUtils.isBlank(param.getPageFieldCode())||
 StringUtils.isBlank(param.getPageFieldName())||
 StringUtils.isBlank(param.getDescription())||
 param.getCreateTime() == 0 || param.getUpdateTime() == 0    ){
            result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        //进行字符串的数字验证
        int success = pageFieldService.updatePageField(param);
        if (success == 0) {
            result.setCode(Constant.RESPONSE_UPDATE_ERROR_CODE);
            result.setMsg(Constant.RESPONSE_UPDATE_ERROR_MSG);
        }
        return result;
    }
    @Transactional
    @ResponseBody
    @ApiOperation(value = "删除模块名", notes = "删除模块名")
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    public BaseVo deletePageField(@RequestParam String pageFieldIds) {
       BaseVo result = new BaseVo();
        if (StringUtils.isBlank(pageFieldIds)) {
           result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
           result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
           return result;
        }
        int success = pageFieldService.deletePageFieldList(pageFieldIds);
       if (success == 0) {
           result.setCode(Constant.RESPONSE_DELETE_ERROR_CODE);
           result.setMsg(Constant.RESPONSE_DELETE_ERROR_MSG);
       }
        return result;
    }
    @ResponseBody
   @ApiOperation(value = "查询模块名", notes = "查询模块名")
    @RequestMapping(value = "/select", method = RequestMethod.GET)
   public BaseVo selectPageField(@RequestParam(required = false) String companyNumber,
                                @RequestParam(required = false) String appNumber,
                                @RequestParam String lang,
                               @RequestParam(required = false) String key,
                              @RequestParam(required = false, defaultValue = "0") long order,
                                @RequestParam int pageIndex,
                                @RequestParam int pageSize) {
        BaseVo result = new BaseVo();
        if (StringUtils.isBlank(lang) || pageIndex == 0 || pageSize == 0) {
           result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
           result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
           return result;
        }
        if (appNumber != null && StringUtils.isBlank(appNumber)) {
            result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        if (companyNumber != null && StringUtils.isBlank(companyNumber)) {
            result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        PageFieldBackVo pageFieldBackVo = new PageFieldBackVo();
        List<PageFieldSelectVo> pageFieldSelectVoList = new ArrayList<>();
        PageFieldSelectParam pageFieldSelectParam = new PageFieldSelectParam();
        List<PageField> pageFieldList = pageFieldService.selectPageField(pageFieldSelectParam);
        pageFieldList.forEach(pageField->pageFieldSelectVoList.add(new PageFieldSelectVo(pageField)));
        pageFieldBackVo.setPageFieldList(pageFieldSelectVoList);
        pageFieldBackVo.setCount(pageFieldService.countPageField(pageFieldSelectParam));
        result.setData(pageFieldBackVo);
        return result;
    }
    @ResponseBody
    @ApiOperation(value = "查看模块名信息", notes = "查看模块名信息")
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public BaseVo selectPageField(@RequestParam String pageFieldId) {
        BaseVo result = new BaseVo();
       if (StringUtils.isBlank(pageFieldId) || !StringUtils.isNumeric(pageFieldId)) {
            result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        PageField   pageField = pageFieldService.getPageField(Long.parseLong(pageFieldId));
       //自定义不存在错误
        if (pageField == null) {
           result.setCode(111);
            result.setMsg("自定义不存在错误");
            return result;
        }
        PageFieldInfoVo pageFieldInfoVo = new PageFieldInfoVo(pageField);
        result.setData(pageFieldInfoVo);
        return result;
   }
}
